 package client;

 import com.alibaba.druid.pool.DruidPooledConnection;
 import database.DatabaseConnection;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import tools.Randomizer;











 public class MapleCoreAura
 {
   private int id;
   private int level;
   private int str;
   private int dex;
   private int int_;
   private int luk;
   private int watk;
   private int magic;
   private long expiration;

   public MapleCoreAura() {}

   public MapleCoreAura(int chrId) {
/*  35 */     this.id = chrId;
   }

   public MapleCoreAura(int chrId, int chrlevel) {
/*  39 */     this.id = chrId;
/*  40 */     this.level = chrlevel;
   }





   public static MapleCoreAura loadFromDb(int chrId) {
/*  48 */     return loadFromDb(chrId, -1);
   }

   public static MapleCoreAura loadFromDb(int chrId, int chrlevel) {
/*  52 */     try (DruidPooledConnection con = DatabaseConnection.getInstance().getConnection()) {
/*  53 */       MapleCoreAura ret = new MapleCoreAura(chrId);
/*  54 */       PreparedStatement ps = con.prepareStatement("SELECT * FROM character_coreauras WHERE characterid = ?");
/*  55 */       ps.setInt(1, chrId);
/*  56 */       ResultSet rs = ps.executeQuery();
/*  57 */       if (!rs.next()) {
/*  58 */         rs.close();
/*  59 */         ps.close();
/*  60 */         return null;
       }
/*  62 */       ret.setLevel((chrlevel > 0) ? chrlevel : rs.getInt("level"));
/*  63 */       long expire = rs.getLong("expiredate");
/*  64 */       if (System.currentTimeMillis() > expire) {
/*  65 */         ret.resetCoreAura();
/*  66 */         ret.saveToDb(con);
       } else {
/*  68 */         ret.setStr(rs.getInt("str"));
/*  69 */         ret.setDex(rs.getInt("dex"));
/*  70 */         ret.setInt(rs.getInt("int"));
/*  71 */         ret.setLuk(rs.getInt("luk"));
/*  72 */         ret.setWatk(rs.getInt("watk"));
/*  73 */         ret.setMagic(rs.getInt("magic"));
/*  74 */         ret.setExpiration(expire);
       }
/*  76 */       rs.close();
/*  77 */       ps.close();
/*  78 */       return ret;
/*  79 */     } catch (SQLException ex) {
/*  80 */       System.err.println("加载龙的传人宝盒信息出错" + ex);
/*  81 */       return null;
     }
   }




   public static MapleCoreAura createCoreAura(int chrId, int chrlevel) {
/*  89 */     MapleCoreAura ret = new MapleCoreAura(chrId, chrlevel);
/*  90 */     try (DruidPooledConnection con = DatabaseConnection.getInstance().getConnection()) {
/*  91 */       PreparedStatement ps = con.prepareStatement("SELECT * FROM character_coreauras WHERE characterid = ?");
/*  92 */       ps.setInt(1, chrId);
/*  93 */       ResultSet rs = ps.executeQuery();
/*  94 */       if (rs.next()) {
/*  95 */         ps.close();
/*  96 */         rs.close();
/*  97 */         ret = loadFromDb(chrId, chrlevel);
/*  98 */         return ret;
       }
/* 100 */       ps.close();
/* 101 */       rs.close();

/* 103 */       ret.resetCoreAura();
/* 104 */       ps = con.prepareStatement("INSERT INTO `character_coreauras` (`characterid`, `level`, `str`, `dex`, `int`, `luk`, `watk`, `magic`, `expiredate`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)");
/* 105 */       ps.setInt(1, chrId);
/* 106 */       ps.setInt(2, chrlevel);
/* 107 */       ps.setInt(3, ret.getStr());
/* 108 */       ps.setInt(4, ret.getDex());
/* 109 */       ps.setInt(5, ret.getInt());
/* 110 */       ps.setInt(6, ret.getLuk());
/* 111 */       ps.setInt(7, ret.getWatk());
/* 112 */       ps.setInt(8, ret.getMagic());
/* 113 */       ps.setLong(9, ret.getExpiration());
/* 114 */       ps.executeUpdate();
/* 115 */       ps.close();
/* 116 */     } catch (SQLException ex) {
/* 117 */       System.err.println("创建龙的传人宝盒信息出错 " + ex);
/* 118 */       return null;
     }
/* 120 */     return ret;
   }





   public void resetCoreAura() {
/* 128 */     this.str = 5;
/* 129 */     this.dex = 5;
/* 130 */     this.int_ = 5;
/* 131 */     this.luk = 5;
/* 132 */     this.watk = 0;
/* 133 */     this.magic = 0;
/* 134 */     this.expiration = System.currentTimeMillis() + 86400000L;
   }




   public void randomCoreAura(int type) {
/* 141 */     int max = Randomizer.nextBoolean() ? ((type == 4) ? 32 : ((type == 3) ? 25 : ((type == 2) ? 20 : 15))) : ((type == 4) ? 25 : ((type == 3) ? 20 : ((type == 2) ? 15 : 10)));
/* 142 */     int min = Randomizer.nextBoolean() ? 5 : 1;
/* 143 */     this.str = Randomizer.rand(min, max);
/* 144 */     this.dex = Randomizer.rand(min, max);
/* 145 */     this.int_ = Randomizer.rand(min, max);
/* 146 */     this.luk = Randomizer.rand(min, max);
/* 147 */     if (Randomizer.nextInt(1000) == 1) {
/* 148 */       this.watk = Randomizer.rand(10, 32);
/* 149 */     } else if (Randomizer.nextInt(500) == 1) {
/* 150 */       this.watk = Randomizer.rand(10, 25);
/* 151 */     } else if (Randomizer.nextInt(200) == 1) {
/* 152 */       this.watk = Randomizer.rand(5, 20);
/* 153 */     } else if (Randomizer.nextInt(100) == 1) {
/* 154 */       this.watk = Randomizer.rand(5, 15);
     } else {
/* 156 */       this.watk = Randomizer.rand(0, 15);
     }
/* 158 */     if (Randomizer.nextInt(1000) == 1) {
/* 159 */       this.magic = Randomizer.rand(10, 32);
/* 160 */     } else if (Randomizer.nextInt(500) == 1) {
/* 161 */       this.magic = Randomizer.rand(10, 25);
/* 162 */     } else if (Randomizer.nextInt(200) == 1) {
/* 163 */       this.magic = Randomizer.rand(5, 20);
/* 164 */     } else if (Randomizer.nextInt(100) == 1) {
/* 165 */       this.magic = Randomizer.rand(5, 15);
     } else {
/* 167 */       this.magic = Randomizer.rand(0, 15);
     }
   }




   public void saveToDb(DruidPooledConnection con) {
/* 175 */     boolean needclose = false;
     try {
/* 177 */       if (con == null) {
/* 178 */         needclose = true;
/* 179 */         con = DatabaseConnection.getInstance().getConnection();
       }
/* 181 */       PreparedStatement ps = con.prepareStatement("UPDATE `character_coreauras` SET `level` = ?, `str` = ?, `dex` = ?, `int` = ?, `luk` = ?, `watk` = ?, `magic` = ?, `expiredate` = ? WHERE `characterid` = ?");
/* 182 */       ps.setInt(1, this.level);
/* 183 */       ps.setInt(2, this.str);
/* 184 */       ps.setInt(3, this.dex);
/* 185 */       ps.setInt(4, this.int_);
/* 186 */       ps.setInt(5, this.luk);
/* 187 */       ps.setInt(6, this.watk);
/* 188 */       ps.setInt(7, this.magic);
/* 189 */       ps.setLong(8, this.expiration);
/* 190 */       ps.setInt(9, this.id);
/* 191 */       ps.executeUpdate();
/* 192 */       ps.close();
/* 193 */     } catch (SQLException ex) {
/* 194 */       System.err.println("保存龙的传人宝盒出错" + ex);
     } finally {
/* 196 */       if (con != null && needclose) {
         try {
/* 198 */           con.close();
/* 199 */         } catch (SQLException e) {
/* 200 */           e.printStackTrace();
         }
       }
     }
   }





   public int getId() {
/* 211 */     return this.id;
   }





   public int getLevel() {
/* 219 */     return this.level;
   }

   public void setLevel(int level) {
/* 223 */     this.level = level;
   }








   public int getCoreAuraLevel() {
/* 234 */     if (this.level >= 30 && this.level < 70)
/* 235 */       return 1; 
/* 236 */     if (this.level >= 70 && this.level < 120)
/* 237 */       return 2; 
/* 238 */     if (this.level >= 120 && this.level < 160)
/* 239 */       return 3; 
/* 240 */     if (this.level >= 160) {
/* 241 */       return 4;
     }
/* 243 */     return 1;
   }




   public int getStr() {
/* 250 */     return this.str;
   }

   public void setStr(int str) {
/* 254 */     this.str = str;
   }




   public int getDex() {
/* 261 */     return this.dex;
   }

   public void setDex(int dex) {
/* 265 */     this.dex = dex;
   }




   public int getInt() {
/* 272 */     return this.int_;
   }

   public void setInt(int int_) {
/* 276 */     this.int_ = int_;
   }




   public int getLuk() {
/* 283 */     return this.luk;
   }

   public void setLuk(int luk) {
/* 287 */     this.luk = luk;
   }




   public int getWatk() {
/* 294 */     return this.watk;
   }

   public void setWatk(int watk) {
/* 298 */     this.watk = watk;
   }




   public int getMagic() {
/* 305 */     return this.magic;
   }

   public void setMagic(int magic) {
/* 309 */     this.magic = magic;
   }




   public int getTotal() {
/* 316 */     return this.str + this.dex + this.int_ + this.luk + this.watk + this.magic;
   }




   public long getExpiration() {
/* 323 */     return this.expiration;
   }

   public void setExpiration(long expire) {
/* 327 */     this.expiration = expire;
   }
 }


/* Location:              C:\PGX\Server.jar!\client\MapleCoreAura.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */